package cda.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class QRCodeCDA extends Activity{
    
    public static String                TYPE = "EAN_13";
    public static String                DONNEES = "1111111111141";
    //AndroidBarcodeView view = new AndroidBarcodeView(this);
    //setContentView(view);
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViewById(R.id.scan_anything).setOnClickListener(scanAnything);
        findViewById(R.id.affiche).setOnClickListener(afficheQRCode);
    }  
    
    public final Button.OnClickListener scanAnything = new Button.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            startActivityForResult(intent, 0);
        }
    };
    
    public final Button.OnClickListener afficheQRCode = new Button.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), AfficheCode.class);
            startActivity(intent);
        }
    };
 
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                DONNEES = intent.getStringExtra("SCAN_RESULT");
                TYPE = intent.getStringExtra("SCAN_RESULT_FORMAT");
                Toast.makeText(this, TYPE, Toast.LENGTH_LONG).show();
            } else if (resultCode == RESULT_CANCELED) {
                Toast.makeText(this, "Echec", Toast.LENGTH_LONG).show();
            }
        }
    }
}
